package com.homework;

import java.util.Random;

public class demo05 {
    public static void main(String[] args) {
        //定义数组
        int[][] arr = new int[2][3];
        //随机数
        Random r = new Random();
        //遍历数组并赋值
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                arr[i][j] = r.nextInt(1, 101);
            }
        }
        //遍历打印
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
        //定义最大值
        int max = arr[0][0];
        //遍历比较大小，比max大的将该值赋给max，依次进行
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                if (max < arr[i][j]) {
                    max = arr[i][j];
                }
            }
        }
        System.out.println("max=" + max);
        //定义新数组，用来接收每组的最大值
        int[] arr01 = new int[2];
        for (int i = 0; i < arr.length; i++) {
            //定义临时最大值，每轮内循环结束后重新赋值
            int temp = arr[i][0];
            for (int j = 0; j < arr[i].length; j++) {
                if (temp < arr[i][j]) {
                    temp = arr[i][j];
                }
                //新数组arr01接收每组最大值
                arr01[i] = temp;
            }
        }
        for (int i = 0; i < arr01.length; i++) {
            System.out.print(arr01[i] + " ");
        }
    }
}
